<?php

/**
 * Description of Util
 \* www.teuker.nl - mail@teuker.nl
 *
 * @author francisc
 */
class Util {
	const RESERVATION_NEW_TODAY = 1;
	const RESERVATION_CANCELATION_TODAY = 2;
	const RESERVATION_NEW_GROUP_TODAY = 3;
	const RESERVATION_CANCELATION_GROUP_TODAY = 4;
	const RESERVATION_NEW_WITH_REMAKRS = 5;

	const TYPE_STRING_NEW_TODAY = 'new_today';
	const TYPE_STRING_CANCELLED_TODAY = 'cancelled_today';
	const TYPE_STRING_NEW_GROUP_TODAY = 'new_group_today';
	const TYPE_STRING_CANCELLED_GROUP_TODAY = 'cancelled_group_today';
	const TYPE_STRING_NEW_WITH_REMARKS = 'new_with_remarks';

	const REASON_RESERVATION_NEW_CONFIRMATION="thankyou";
	const REASON_RESERVATION_UPDATE_CONFIRMATION="changed";
	const REASON_RESERVATION_CANCEL="cancelled";

	/*********************************************************************************/
	public static function loadI18NHelper() {
		sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');
	}

	/*********************************************************************************/
	public static function getAllDaysIntervals($restaurant_id) {
		$day_intervals = array();
		for ($i = 1; $i <= 7; $i++) {
			$day_intervals[$i] = SqlEngine::getDayIntervalsInfo(array('day' => $i, 'restaurant_id' => $restaurant_id));
		}

		return $day_intervals;
	}

	/*********************************************************************************/
	public static function convertDateServerClient($date, $locale = "nl") {
		Util::loadHelper('Date');
		switch ($locale) {
			case "en":
				$date = format_date($date, 'MM/dd/yyyy');
				break;
			default:
				$date = format_date($date, 'dd/MM/yyyy');
			break;
		}

		return $date;
	}

	/********************************************************************************/
	public static function convertDateClientServer($date, $locale = "nl") {
		if ('' == $date || null == $date)
			return null;

		switch ($locale) {
			case "en":
			case "nl":
				$separator = "/";
				break;
			default:
				$separator = "-";
			break;
		}

		$date_info = explode($separator, $date);

		if (3 !== count($date_info))
			return null;

		switch ($locale) {
			case "en":
				$day = $date_info[1];
				$month = $date_info[0];
				$year = $date_info[2];
				break;
			case "nl":
				$day = $date_info[0];
				$month = $date_info[1];
				$year = $date_info[2];
				break;
			default: /* defaults to EN */
				$day = $date_info[1];
			$month = $date_info[0];
			$year = $date_info[2];
			break;
		}

		$date_for_server = $year . '-' . $month . '-' . $day;

		return $date_for_server;
	}

	/*********************************************************************************/
	public static function getDate($flag = null) {
		if ('today' == $flag)
			return date('y-m-d');

		return date('d-m-y');
	}

	/*********************************************************************************/
	public static function isToday($date) {

		return date('Y-m-d') == $date;
	}

	public static function isTomorrow($date) {
		$tomorrow = date('Y-m-d', mktime(0,0,0,date('m'), date('d') + 1, date('Y')));

		return $date == $tomorrow;
	}

	/*********************************************************************************/
	//FIXME -> it works now, guess this is obsolete... : Check date sunday
	public static function offsetTodayDate($date, $day_offset) {

		return date('Y-m-d', mktime(0,0,0,date('m'), date('d') + $day_offset, date('Y')));
	}

	/*********************************************************************************/
	public static function getDayText($date) {

		return date('l', Util::dateToTimestamp($date));
	}

	/*********************************************************************************/
	public static function decideDayIndex($date) {

		return $dw = date("w", Util::dateToTimestamp($date));
	}

	/**
	 * Index from 1 to 7. Monday is first date
	 * @param $date
	 * @since  26.04.2012
	 * @user  Kristian
	 */
	public static function decideDayIndexMondayFirst($date) {

		return $dw = ((date("w", Util::dateToTimestamp($date))+6)%7)+1;
	}

	/*********************************************************************************/
	public static function getShortDate($date) {
		$date_timestamp = Util::dateToTimestamp($date);

		return date("D", $date_timestamp) . ' ' . date("d", $date_timestamp) . ' ' . date("M", $date_timestamp);
	}

	/*********************************************************************************/
	public static function dateToTimestamp($date) {
		list($year, $month, $day) = explode('-', $date);

		return mktime(0, 0, 0, $month, $day, $year);
	}

	/*********************************************************************************/
	public static function loadHelper($helper) {
		sfContext::getInstance()->getConfiguration()->loadHelpers($helper);
	}

	/*********************************************************************************/
	public static function decide_message_type($message) {
		$user = sfContext::getInstance()->getUser();

		if (!empty($message['comments_diet']) || !empty($message['comments_internal'])||!empty($message['comments_general']))
			return Util::RESERVATION_NEW_WITH_REMAKRS;

		if (date('Y-m-d') == $message['date'] && $message['person_no'] > 10 && empty($message['deleted_at']))
			return Util::RESERVATION_NEW_GROUP_TODAY;

		if (date('Y-m-d') == $message['date'] && $message['person_no'] > 10 && !empty($message['deleted_at']))
			return Util::RESERVATION_CANCELATION_GROUP_TODAY;

		if (date('Y-m-d') == $message['date'] && empty($message['deleted_at']))
			return Util::RESERVATION_NEW_TODAY;

		if (date('Y-m-d') == $message['date'] && !empty($message['deleted_at']))
			return Util::RESERVATION_CANCELATION_TODAY;
	}

	/*********************************************************************************/
	public static function is_group_reservation($person_no) {
		$restaurant_id = sfContext::getInstance()->getUser()->getAttribute('current_restaurant_id');

		if (null == $restaurant_id)
			return false;

		$settings = SqlEngine::getSettings(array('restaurant_id' => $restaurant_id));

		if ($person_no >= $settings['group_size'])
			return true;

		return false;
	}

	/*********************************************************************************/
	public static function retrieve_cookie_array($cookie) {

		return get_magic_quotes_gpc() ? unserialize(stripslashes($cookie)) : unserialize($cookie);
	}

	/*********************************************************************************/
	public static function init_mailer() {
		$mailer = sfContext::getInstance()->getMailer();
		$user = sfContext::getInstance()->getUser();

		$mailer->getRealtimeTransport()->setUsername($user->getAttribute('restaurant_email_backup'));
		$mailer->getRealtimeTransport()->setPassword($user->getAttribute('restaurant_email_backup_password'));

		return $mailer;
	}

	/**
	 * Get template from SQL engine mechanism
	 * @param $type template type
	 * @param $category template categorory
	 * @return template object
	 * @since  29.04.2012
	 * @user  Kristian
	 *
	 */
	public static function getTemplate($type, $category) {
		$template_types = SqlEngine::getTemplateTypes(array('name' => $type));
		$template_category = SqlEngine::getTemplateCategory(array('name' => $category));

		$template = SqlEngine::getTemplates(array('category_id' => $template_category[0]['template_category_id'],
				'type_id' => $template_types[0]['template_type_id']));

		return $template[0];
	}

	/**
	 * Replace all parameters placeholders from the array
	 * @param $message
	 * @param $replace_holders
	 * @param $senderRole not used for the moment
	 * @return the same structure array as $message parameter but withoug placeholders,populated
	 * @since  29.04.2012
	 * @user  Kristian
	 */
	private static function replaceEmailBodyPlaceholders($message,$replace_holders,$senderRole){
		$body=$message['body'];
		$subject=$message['subject'];

		//body
		$body = str_replace('##salutation##', $replace_holders['body']['salutation'], $body);
		$body = str_replace('##reservation_time_date##', $replace_holders['body']['reservation_time_date'], $body);
		$body = str_replace('##remark##', $replace_holders['body']['remark'], $body);
		$body = str_replace('##internal##', $replace_holders['body']['internal'], $body);
		$body = str_replace('##deep_link_reservation##', $replace_holders['body']['deep_link_reservation'], $body);
		$body = str_replace('##group##', $replace_holders['body']['group'], $body);
		$body = str_replace('##date##', $replace_holders['body']['date'], $body);
		$body = str_replace('##time##', $replace_holders['body']['time'], $body);
		$body = str_replace('##guestname##',$replace_holders['body']['guestname'], $body);
		$body = str_replace('##guesttel##', $replace_holders['body']['guesttel'], $body);
		$body = str_replace('##guestaddress##',$replace_holders['body']['guestaddress'], $body);
		$body = str_replace('##persons##',$replace_holders['body']['persons'], $body);
		$body = str_replace('##occasion##',$replace_holders['body']['occasion'], $body);

		$subject = str_replace('##date##',$replace_holders['body']['occasion'], $subject);
		$subject = str_replace('##time##',$replace_holders['body']['time'], $subject);
		$subject = str_replace('##guestname##',$replace_holders['body']['guestname'], $subject);
		$subject = str_replace('##guesttel##',$replace_holders['body']['guesttel'], $subject);
		$subject = str_replace('##guestaddress##',$replace_holders['body']['guestaddress'], $subject);
		$subject = str_replace('##persons##',$replace_holders['body']['persons'], $subject);

		$message['body']=$body;
		$message['subject']=$subject;
		return $message;
		
	}

	/**
	 * Replace a message
	 * @param String $message
	 * @param int $hours
	 * @return processed message 
	 */
	public static function replaceHourPlaceHolder($message,$hours){
		return str_replace('##hours##',$hours, $message);
	}




	/**
	 *  Send an email to the guest for confirmation
	 * @param $form_data
	 * @param $token
	 * @param $reservation_id
	 * @since  29.04.2012
	 * @user  Kristian
	 */
	public static function send_thank_you_email($reservation) {
		Util::send_generic_notification_email($reservation,Util::REASON_RESERVATION_NEW_CONFIRMATION);
	}

	/**
	 * Notification email specific when email is updated
	 * @param $reservation
	 * @since  30.04.2012
	 * @user  Kristian
	 */
	public static function send_update_email($reservation) {
		Util::send_generic_notification_email($reservation,Util::REASON_RESERVATION_UPDATE_CONFIRMATION);
	}


	/**
	 *
	 * @param $reservation reservation full object as is in database
	 * @param $notification_reason on of these values REASON_RESERVATION_NEW_CONFIRMATION,REASON_RESERVATION_UPDATE_CONFIRMATION,REASON_RESERVATION_UPDATE_CONFIRMATION
	 * @since  30.04.2012
	 * @user  Kristian
	 */
	protected static function send_generic_notification_email(&$reservation,$notification_reason) {
		Util::loadHelper('Partial');
		Util::loadHelper('I18N');
		$user = sfContext::getInstance()->getUser();
		$mailer = Util::init_mailer();
		$template_user='';
		$template_manager='';

		switch($notification_reason){
			case Util::REASON_RESERVATION_NEW_CONFIRMATION:{
				$template_user=Util::REASON_RESERVATION_NEW_CONFIRMATION;
				$template_manager='manager new';
				break;
			}
			case Util::REASON_RESERVATION_UPDATE_CONFIRMATION:{
				$template_user=Util::REASON_RESERVATION_UPDATE_CONFIRMATION;
				$template_manager='manager change';
				break;
			}
			case Util::REASON_RESERVATION_CANCEL:{
				$template_user=Util::REASON_RESERVATION_CANCEL;
				$template_manager='manager change';
				break;
			}

		}


		$template = Util::getTemplate('email', $template_user);


		$hasgroup_b = (  $reservation['person_no'] >= $user->getAttribute('group_size') ? 1 : 0 );
		$hasremark_b = (null !=$reservation['comments_diet'] ? 1 : 0 );
		$hasinternal_b = (null != $reservation['comments_internal'] ? 1 : 0 );

		/* prep body */
		$body = $template['body'];
		$deep_link = "http://{$_SERVER['HTTP_HOST']}/show/" . $reservation['token'];

		$salutation = get_partial('email/full_salutation', array('salutation' => $reservation['salutation'],
				'name_first' => $reservation['name_first'],
				'name_last' => $reservation['name_last']));

		$reservation_date_time = get_partial('email/thank_you_reservation_summary',
				array('date' => $reservation['date'],
						'time' => $reservation['time'],
						'person_no' => $reservation['person_no']));

		$remark = get_partial('email/remark', array('diet' => $reservation['comments_diet']));

		$group_menu = '';
		if ($hasgroup_b) {
			$menu = SqlEngine::getMenus(array('menu_id' => $reservation['menu_id'],'restaurant_id' =>SqlEngine::getRestaurantsfromReservationId($reservation['reservation_id'])));
			$group_menu = get_partial('email/group_menu');

			$placeholders['body']['group_menu']=$menu[0]['name'];
			$placeholders['body']['group_menu_description']=$menu[0]['description'];

			$group_menu = str_replace('##group_menu##', $menu[0]['name'], $group_menu);
			$group_menu = str_replace('##group_menu_description##', $menu[0]['description'], $group_menu);
		}

		$guesttel = '';
		$guesttel .= ( null != $reservation['phone'] ? '<strong>t.</strong> ' .  $reservation['phone'] . '<br />' : '' );
		$guesttel .= ( null != $reservation['mobile'] ? '<strong>m.</strong> ' .  $reservation['mobile'] . '<br />' : '' );
			
		$deep_link = "http://{$_SERVER['HTTP_HOST']}/show/" . $reservation['token'];

		$placeholders['body']['salutation']=$salutation;
		$placeholders['body']['reservation_time_date']=$reservation_date_time;
		$placeholders['body']['remark']=$remark;
		$placeholders['body']['internal']='';
		$placeholders['body']['group']=$group_menu;
		$placeholders['body']['date']=$reservation['date'];
		$placeholders['body']['time']= $reservation['time'];
		$placeholders['body']['guestname']=$reservation['name_first'] .'   '.$reservation['name_last'] ;
		$placeholders['body']['guesttel']=$guesttel;
		$placeholders['body']['guestaddress']=$reservation['address'];
		$placeholders['body']['persons']= $reservation['person_no'];
		$placeholders['body']['occasion']= $reservation['occasion'];
		$placeholders['body']['deep_link_reservation']=$deep_link;

			

		$placeholders['subject']['date']=$reservation['date'];
		$placeholders['subject']['time']= $reservation['time'];
		$placeholders['subject']['guestname']= $reservation['name_first'] .'   '.$reservation['name_last'] ;
		$placeholders['subject']['guesttel']=$deep_link;
		$placeholders['subject']['guestaddress']=$reservation['address'];
		$placeholders['subject']['persons'] =$reservation['person_no'];


		//replace placeholders
		$email_msg['body']=$body;
		$email_msg['subject']= $template['subject'];
		$email_replacement=Util::replaceEmailBodyPlaceholders($email_msg,$placeholders,0);
		$body=$email_replacement['body'];
		$subject=$email_replacement['subject'];

		/* attach the header and the footer */
		$body = $user->getAttribute('restaurant_email_header') . $body . $user->getAttribute('restaurant_email_footer');


		/* send update confirmation email to the user */
		$message = $mailer->compose(array('office@dudok.nl' => $user->getAttribute('restaurant_email_from')),

				$reservation['email'],
				$template['subject'],
				$body);


		$message->setContentType('text/html');
		$mailer->send($message);




		switch($notification_reason){
			case Util::REASON_RESERVATION_NEW_CONFIRMATION:{


				/* send backup email to the restaurant email address */
				$subject = $user->getAttribute('restaurant_name') . ' ' . Util::convertDateServerClient($reservation['date'])
				. ' ' .$reservation['time']
				. ' - ' . __('New reservation') . ' - ' . $reservation['name_last']
				. ', ' . $reservation['person_no'] . ' ' . __('persons');

				/* update the reservation log */
				$message = __('confirmation sent to') . ': ' . $reservation['email']. $subject . '.' ;
				SqlEngineCore::get()->insert(array('table' => 'reservation_log',
						'columns' => array(
								'reservation_id' => $reservation['reservation_id'],
								'user_id' => $user->getAttribute('user_id'),
								'message' => $message,
								'created_at' => 'NOW()')));




				break;
			}
			case Util::REASON_RESERVATION_UPDATE_CONFIRMATION:{


				/* send backup email to the backup email address */
				$subject = $user->getAttribute('restaurant_name') . ' ' . Util::convertDateServerClient($reservation['date'])
				. ' ' . $reservation['time']
				. ' - ' . __('Changed reservation') . ' - ' . $reservation['name_last']
				. ', ' . $reservation['person_no'] . ' ' . __('persons');



				/* update the reservation log */
				SqlEngineCore::get()->insert(array('table' => 'reservation_log',
						'columns' => array(
								'reservation_id' => $reservation['reservation_id'],
								'user_id' => $user->getAttribute('user_id'),
								'message' => __('sent updated reservation mail') . ':  ' .   $reservation['email']. ': ' . $subject . '.',
								'created_at' => 'NOW()')));

				break;
			}
			case Util::REASON_RESERVATION_CANCEL:{
				/* send backup email to the restaurant email address */
				$subject = $user->getAttribute('restaurant_name') . ' ' . Util::convertDateServerClient($reservation['date'])
				. ' ' . $reservation['time']
				. ' - ' . __('Cancelled reservation') . ' - ' . $reservation['name_last']
				. ', ' . $reservation['person_no'] . ' ' . __('persons');
					
				/* update the reservation log */
				SqlEngineCore::get()->insert(array('table' => 'reservation_log',
						'columns' => array(
								'reservation_id' => $reservation['reservation_id'],
								'user_id' => $user->getAttribute('user_id'),
								'message' => __('sent canceled reservation mail') . ':  ' .   $reservation['email']. ': ' . $subject . '.',
								'created_at' => 'NOW()')));

				break;
			}
		}


		$message = $mailer->compose(array('sebastiaan@dudok.nl' => $user->getAttribute('restaurant_email_from')),
				$user->getAttribute('restaurant_email_backup') . '',
				$subject,
				$body);

		$message->setContentType('text/html');
		$mailer->send($message);



		/*******************************************************************************
		 * 	send email to the   M A N A G E R   on group menu or diet/internal comments
		* *****************************************************************************/




		if (( $hasgroup_b + $hasinternal_b + $hasremark_b > 0) ||($notification_reason==Util::REASON_RESERVATION_CANCEL) ||($notification_reason==Util::REASON_RESERVATION_UPDATE_CONFIRMATION) ) {

			$template = Util::getTemplate('email', $template_manager);
			$body = $template['body'];
			$reservation_date_time = get_partial('email/thank_you_reservation_summary',
					array('date' => $reservation['date'],
							'time' => $reservation['time'],
							'person_no' => $reservation['person_no']));


			$remark = '-- ' . __('no remarks') . ' --';
			if ($hasremark_b) {
				$remark = $reservation['comments_diet'];
			}

			$internal = '-- ' . __('no remarks') . ' --';
			if ($hasinternal_b) {
				$internal =  $reservation['comments_internal'];
			}


			$placeholders['body']['salutation']=$salutation;
			$placeholders['body']['$reservation_date_time']=$reservation_date_time;
			$placeholders['body']['remark']=$remark;
			$placeholders['body']['internal']=$internal;
			$placeholders['body']['group']=$group_menu;
			$placeholders['body']['date']=$reservation['date'];
			$placeholders['body']['time']= $reservation['time'];
			$placeholders['body']['guestname']=$reservation['name_first'] .'   '.$reservation['name_last'] ;
			$placeholders['body']['guesttel']=$guesttel;
			$placeholders['body']['guestaddress']=$reservation['address'];
			$placeholders['body']['persons']= $reservation['person_no'];
			$placeholders['body']['occasion']= $reservation['occasion'];
			$placeholders['body']['deep_link_reservation']=$deep_link;



			$placeholders['subject']['date']=$reservation['date'];
			$placeholders['subject']['time']= $reservation['time'];
			$placeholders['subject']['guestname']= $reservation['name_first'] .'   '.$reservation['name_last'] ;
			$placeholders['subject']['guesttel']=$deep_link;
			$placeholders['subject']['guestaddress']=$reservation['address'];
			$placeholders['subject']['persons'] =$reservation['person_no'];


			//replace placeholders
			$email_msg['body']=$body;
			$email_msg['subject']= $template['subject'];
			$email_replacement=Util::replaceEmailBodyPlaceholders($email_msg,$placeholders,0);
			$body=$email_replacement['body'];
			$subject=$email_replacement['subject'];



			$message = $mailer->compose(array('office@dudok.nl' => 'dudok.nl'),
					$user->getAttribute('restaurant_email_manager'),
					$subject,
					$body);

			$message->setContentType('text/html');
			$mailer->send($message);

			/* update the reservation log */
			$message = __('manager notice sent to') . ' - ' . $subject . ': ' . $user->getAttribute('restaurant_email_manager');
			SqlEngineCore::get()->insert(array('table' => 'reservation_log',
					'columns' => array(
							'reservation_id' => $reservation['reservation_id'],
							'user_id' => $user->getAttribute('user_id'),
							'message' => $message,
							'created_at' => 'NOW()')));

		}
	}

	/*********************************************************************************/
	public static function send_cancellation_email($reservation) {
		Util::send_generic_notification_email($reservation,Util::REASON_RESERVATION_CANCEL);
	}

	/*********************************************************************************/
	public static function is_seat_limit($person_no, $date, $time_hour, $time_minute, $user) {
		$restaurant_id = $user->getAttribute('current_restaurant_id');

		if (null == $date)
			return false;

		/* this should not happen */
		if (null == $restaurant_id)
			return sfView::NONE;

		$day_of_the_week = date('N', strtotime($date));
		$full_time = $time_hour . ':' . $time_minute;

		$intervals = SqlEngine::getDayIntervalsInfo(array('day' => $day_of_the_week,
				'restaurant_id' => $restaurant_id,
				'time' => $full_time));
		//var_dump($intervals);
		if (empty($intervals))
			return false;

		$seat_limit = $intervals[0]['seats'];

		/* get the total seats already reserved */
		$already_taken_seats = 0;
		$reservations = SqlEngine::getReservations(array('restaurant_id' => $restaurant_id,
				'date' => $date,
				'not_deleted'=>1,
				'time_between' => array($intervals[0]['time_start'], $intervals[0]['time_end'])));
		foreach ($reservations as $reservation)
			$already_taken_seats += $reservation['person_no'];

		if ($already_taken_seats + $person_no > $seat_limit)
			return true;

		return false;
	}

	/*********************************************************************************/
	public static function is_block_time($date, $time_hour, $time_minute, $user) {
		$full_time = $time_hour . ':' . $time_minute;

		$restaurant_id = $user->getAttribute('current_restaurant_id');

		if (null == $restaurant_id || null == $date)
			return false;

		$blocked_times = SqlEngine::getBlockTimes(array('restaurant_id' => $restaurant_id,
				'date' => $date,
				'time' => $full_time));
		if (0 == count($blocked_times))
			return array('is_block_time' => false);

		return array('is_block_time' => true, 'reason' => $blocked_times[0]['reason']);

		//        if (0 == count($blocked_times))
		//            return false;
		//
		//        return true;
	}

	/**
	 * Get an associative array with all ten days from current date containing close status for each
	 * @param Date $date from which date to begin
	 * @param int $restaurant_id
	 */
	public static function getNextTenDaysStatus($date,$restaurant_id){
		$days_interval=10;
		$date = date("Y-m-d");// current date
		$days=array();

		//1 get  a query with all special days from on to next ten days and check one my one
		//settings_special_date
		$specialDays=SqlEngine::getSpecialDates(array('restaurant_id' => array('value' => $restaurant_id, 'type' => PDO::PARAM_INT),
				'date_end' => strtotime(date("Y-m-d", strtotime($date)) . " +$days_interval day"))
		);
		
		$time_slots_days=Util::getAllDaysIntervals($restaurant_id);

		for ($i=0;$i<$days_interval;$i++){
			$days[$i]['date']=strtotime(date("Y-m-d", strtotime($date)) . " +{$i} day");
			$days[$i]['index']=Util::decideDayIndexMondayFirst($date);
			//search for a closed day
			for ($j=0;$j<$count($specialDays);$j++){
			if ($specialDays[$j]['date']==$days[$i]['date'])
				$days[$i]['closed']="1";
				return;
			}
			//if there is no timeslot for that day we will considered closed that day
			if (count($time_slots_days[Util::decideDayIndexMondayFirst($date)])==0){
				$days[$i]['closed']="1";
			}
			
			//TODO check if is't a block time
		}

	
		//3 get a query that doesn't have block time for that day and is not greather than timeslot


		//4 for each day you will check  first 3 queries
		for ($i=0;$i<$days_interval;$i++){
			// check i
		}

		return $days;

	}
	/*********************************************************************************/
	public static function set_session_info($restaurant, $settings, $user) {
		$user->setAttribute('current_restaurant_id', $restaurant['restaurant_id']);

		$user->setAttribute('restaurant_web',          $settings['web']);
		$user->setAttribute('group_size',              $settings['group_size']);
		$user->setAttribute('restaurant_name',         $restaurant['name']);
		$user->setAttribute('restaurant_phone',        $settings['phone']);
		$user->setAttribute('restaurant_email_header', $settings['email_header']);
		$user->setAttribute('restaurant_email_footer', $settings['email_footer']);
		// HV 19-8
		$user->setAttribute('restaurant_html_header', $settings['header']);
		$user->setAttribute('restaurant_html_footer', $settings['footer']);
		// --
		$user->setAttribute('restaurant_email_backup', $settings['email_backup']);
		$user->setAttribute('restaurant_email_backup_password', $settings['email_backup_password']);
		$user->setAttribute('restaurant_email_from',   $settings['email_from']);
		//
		$user->setAttribute('restaurant_email_manager', $settings['email_manager']);
		 

	}
}
